#include "btform.h"
#include "ui_btform.h"
#include<QDebug>
#include<QRect>
BtForm::BtForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BtForm)
{
    ui->setupUi(this);
    this->Init();

}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::setIcon(QString icon, QString text, int index)
{
    //设置图标，文本；
    ui->btIcon->setPixmap(QPixmap(icon));
    ui->btText->setText(text);
    this->index = index;
}

int BtForm::getIndex()
{
    return index;
}

void BtForm::cleanBtForm()
{
    ui->btStyle->setStyleSheet("#btStyle:hover{background-color:#d8d8d8;}");

}

void BtForm::getPropertyAnimation()
{
    ui->lineBox->show();

}

void BtForm::Init()
{
    //设置动图；
    //line1animation;
    this->line1animation = new QPropertyAnimation(ui->line1,"geometry",this);
    line1animation->setDuration(1000);
    line1animation->setKeyValueAt(0,QRect(0,15,2,0));
    line1animation->setKeyValueAt(0.5,QRect(0,5,2,25));
    line1animation->setKeyValueAt(1,QRect(0,15,2,2));
    line1animation->setLoopCount(-1);
    line1animation->start();

    this->line2animation = new QPropertyAnimation(ui->line2,"geometry",this);
    line2animation->setDuration(1200);
    line2animation->setKeyValueAt(0,QRect(7,15,2,0));
    line2animation->setKeyValueAt(0.5,QRect(7,5,2,25));
    line2animation->setKeyValueAt(1,QRect(7,15,2,2));
    line2animation->setLoopCount(-1);
    line2animation->start();

    this->line3animation = new QPropertyAnimation(ui->line3,"geometry",this);
    line3animation->setDuration(1400);
    line3animation->setKeyValueAt(0,QRect(15,15,2,0));
    line3animation->setKeyValueAt(0.5,QRect(15,5,2,25));
    line3animation->setKeyValueAt(1,QRect(15,15,2,2));
    line3animation->setLoopCount(-1);
    line3animation->start();

    this->line4animation = new QPropertyAnimation(ui->line4,"geometry",this);
    line4animation->setDuration(1600);
    line4animation->setKeyValueAt(0,QRect(22,15,2,0));
    line4animation->setKeyValueAt(0.5,QRect(22,5,2,25));
    line4animation->setKeyValueAt(1,QRect(22,15,2,2));
    line4animation->setLoopCount(-1);
    line4animation->start();
    ui->lineBox->hide();//隐藏lineBox;
}

void BtForm::mousePressEvent(QMouseEvent *event)
{
    //当鼠标按下去时，改变按钮的颜色；
    ui->btStyle->setStyleSheet("#btStyle{background-color:rgb(30,206,154);}");
    //发出信号；
    emit btCliced(this->index);
    (void)event;
}

